home *** CD-ROM | disk | FTP | other *** search
/ Dr. Windows 3 / dr win3.zip / dr win3 / PROGRAMR / OLE2BOOK.ZIP / BASICS.ZIP / CLASSLIB / DOCWIN.CPP < prev    next >
C/C++ Source or Header  |  1993-03-23  |  3KB  |  103 lines

  1. /*
  2.  * DOCWIN.CPP
  3.  * Sample Code Class Libraries
  4.  *
  5.  * Window procedure for document windows.
  6.  *
  7.  * Copyright (c)1993 Microsoft Corporation, All Rights Reserved
  8.  *
  9.  * Kraig Brockschmidt, Software Design Engineer
  10.  * Microsoft Systems Developer Relations
  11.  *
  12.  * Internet  :  kraigb@microsoft.com
  13.  * Compuserve:  >INTERNET:kraigb@microsoft.com
  14.  */
  15.  
  16.  
  17.  
  18. #include <windows.h>
  19. #include "classlib.h"
  20.  
  21.  
  22.  
  23.  
  24. /*
  25.  * DocumentWndProc
  26.  *
  27.  * Purpose:
  28.  *  Document window class that contains a polyline but does not own
  29.  *  things like the gizmobar.
  30.  *
  31.  *  We handle all commands from menus and gizmobars as well as
  32.  *  notifications from the polyline itself.  The frame Schmoo
  33.  *  window just makes sure that commands and such are dispatched
  34.  *  here as necessary, especially in an MDI case.
  35.  */
  36.  
  37. LRESULT __export FAR PASCAL DocumentWndProc(HWND hWnd, UINT iMsg
  38.     , WPARAM wParam, LPARAM lParam)
  39.     {
  40.     LPCDocument     pDoc;
  41.     BOOL            fOK=FALSE;
  42.     LPARAM          lTemp;
  43.     LRESULT         lRet;
  44.  
  45.     //This will be valid for all messages except WM_NCCREATE
  46.     pDoc=(LPCDocument)GetWindowLong(hWnd, DOCWL_STRUCTURE);
  47.  
  48.  
  49.     if (NULL!=pDoc)
  50.         {
  51.         //Call the hook and return its value if it tells us to.
  52.         if (pDoc->FMessageHook(hWnd, iMsg, wParam, lParam, &lRet))
  53.             return lRet;
  54.         }
  55.  
  56.  
  57.     switch (iMsg)
  58.         {
  59.         case WM_CREATE:
  60.             /*
  61.              * Save our object pointer with this window.  We have to
  62.              * do this inside this message since we don't get the
  63.              * MDICREATESTRUCT anywhere else.
  64.              */
  65.  
  66.             lTemp=(LPARAM)((LPCREATESTRUCT)lParam)->lpCreateParams;
  67.             pDoc=(LPCDocument)((LONG)((LPMDICREATESTRUCT)lTemp)->lParam);
  68.  
  69.             //Store with the window--UINT converts to 32-bits.
  70.             SetWindowLong(hWnd, DOCWL_STRUCTURE, (LONG)(LPSTR)pDoc);
  71.             break;
  72.  
  73.  
  74.         case WM_CLOSE:
  75.             //Tell our main window to close us
  76.             if (NULL!=pDoc->m_pAdv)
  77.                 pDoc->m_pAdv->OnCloseRequest(pDoc);
  78.  
  79.             break;
  80.  
  81.  
  82.         case WM_QUERYENDSESSION:
  83.             return TRUE;    //Right now we can always close.
  84.  
  85.  
  86.         case DOCM_PDOCUMENT:
  87.             //Return our object pointer
  88.             return (LONG)(LPSTR)pDoc;
  89.  
  90.         case WM_MDIACTIVATE:
  91.             if (0!=wParam && NULL!=pDoc->m_pAdv)
  92.                 pDoc->m_pAdv->OnActivate(pDoc);
  93.  
  94.             break;
  95.  
  96.  
  97.         default:
  98.             return DEFDOCUMENTPROC(hWnd, iMsg, wParam, lParam);
  99.         }
  100.  
  101.     return 0L;
  102.     }
  103.